package cn.tedu.boot06.controller;

import cn.tedu.boot06.entity.User;
import cn.tedu.boot06.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 作者：HeShaoShuai
 * @Email 邮箱：2569819541@qq.com
 * @Date 日期：2023/5/12 10:16
 * @Package 包名：cn.tedu.boot06.controller
 * @Project 项目名：JavaSE
 * @Version 1.0
 */
@RestController
public class UserController {
	@Autowired
	UserMapper mapper;
	@RequestMapping("/reg")
	public int reg(@RequestBody User user){
		System.out.println("user = " + user);
		User u = mapper.selectByUsername(user.getUsername());
		if (u!=null){
			return 2; //用户名已存在
		}
		mapper.insert(user);
		return 1;//代表注册成功
	}
	@RequestMapping("/login")
	public int login(@RequestBody User user){
		User u = mapper.selectByUsername(user.getUsername());
		if (u!=null){
			if (u.getPassword().equals(user.getPassword())){
				return 1;//登录成功
			}
			return 2;//密码错误
		}
		return 3;//用户名不存在
	}
}